package org.beetl.sql.springboot.service;

import org.beetl.sql.springboot.Db;
import org.beetl.sql.springboot.entity.OrderLog;
import org.beetl.sql.springboot.mapper.OrderLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderLogService {



	@Autowired
	OrderLogMapper orderRewriteMapper;
	public List<OrderLog> logs(int tenantId){
		Db.localValue.set(tenantId);
		return orderRewriteMapper.all();
	}


	public List<OrderLog> queryByName(int tenantId,String name){
		Db.localValue.set(tenantId);
		return orderRewriteMapper.select(name);
	}

	public OrderLog add(int tenantId,String name){
		//对于插入，需要显示的设置tenantId。因为sql重写，只重写了where部分，insert语句没有where
		Db.localValue.set(tenantId);
		OrderLog log = new OrderLog();
		log.setName(name);
		orderRewriteMapper.insert(log);
		return log;
	}

	public List<OrderLog> template(int tenantId,String name){
		Db.localValue.set(tenantId);
		OrderLog log = new OrderLog();
		log.setName(name);
		return orderRewriteMapper.template(log);
	}
}
